package com.example.demo_yunpan.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo_yunpan.entity.user;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.sql.Timestamp;
import java.util.List;

@Mapper
@Repository
public interface UserMapper  extends BaseMapper<user> {
    /**
     *查询所有用户列表
     * */
    @Select("select * from user")
    List<user> getUserByAll();

    /**
     *查询登录账号与密码
     * @param userName,userPass
     * return 查询结果
     * */
    @Select("SELECT * FROM user WHERE user_name = #{userName} AND user_pass = #{userPass}")
    user userLogin(@Param("userName") String userName, @Param("userPass") String userPass);

    /**
     *查询用户是否存在
     * @param userName
     * return 查询结果
     * */
    @Select("select * from user where user_name = #{userName}")
    user selectUserByName(@Param("userName") String userName);

    /**
     * 根据登录账号ID查询登录用户名
     * @param userId
     * return 查询结果
     * */
    @Select("SELECT user_name FROM user WHERE user_id = #{userId} ")
    List<String> selectUserNameByUserId(@Param("userId") String userId);

    /**
     *插入新的用户
     * @param user
     * return 插入结果
     * */
    @Insert("INSERT INTO user (user_name, user_pass, user_phone, register_time ,email)\n" +
            "        VALUES (#{userName},#{userPass},#{userPhone},#{registerTime},#{email});")
    int insertUser(user user);

    /**
     * 查看个人信息
     * @param userId
     * return 查询结果
     * */
    @Select("select * from user where user_id = #{userId}")
    user selectUserById(@Param("userId") String userId);

    /**
     * 修改个人信息
     * @param u
     * return
     * */
    @Update("UPDATE user SET user_name = #{userName}, user_pass = #{userPass} WHERE user_id = #{userId}")
    int updateUser(user u);
}
